class Solution {
public:
    vector<int> dailyTemperatures(vector<int>& temperatures) {
        stack<int> s; // 存下标的单调栈
        int n = temperatures.size();
        vector<int> ret(n);

        for(int i = 0; i < n; ++i)
        {
            while(!s.empty() && temperatures[i] > temperatures[s.top()])
            {
                ret[s.top()] = i - s.top();
                s.pop();
            }
            s.push(i);
        }
        return ret;
    }
};